#!/bin/bash

# Copyright © 2024 Jeffrey Cliff
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

#echo "\$1" $1 "\$2" $2
#exit

DOMAIN=`echo $1 | awk -F'@' '{print $3}'`
check_domain_for_banned_from_spc.sh $DOMAIN
if [[ $? -eq 1 ]]; then
echo "spc banned this server"
exit 1;
fi

DB=/home/themusicgod1/TDL/urls.db
# GRAB SNOWFLAKE
echo "snowflake detection:"
OUT=`sqlite3 $DB -line "select other from news where url like \"%"$1"%\""| awk -F' ' '{print $3}'`;
echo "other is:" $OUT
if [[ -z $OUT ]]; then
echo "blank other";
ID=`sqlite3 /home/themusicgod1/TDL/urls.db -line "select id from news where url = \""$1"\"" | awk -F' ' '{print $3}'`;
echo $ID;
echo $2;
OTHER1=`sqlite3 $DB -line "select url, rss, other, id from news where url = \""$1"\"" | grep url | awk -F' ' '{print $3}'` ;
OTHER2=`getSPCURL.sh $OTHER1`
echo "update news set other = \""$OTHER2"\" where id = "$ID";"
fi
